﻿using System.Data.Common;
using Loong.Dependency;
using Loong.Domain.Uow;

namespace Loong.Dapper.Uow
{
    public class DapperActiveTransactionProvider : IActiveTransactionProvider, ITransientDependency
    {
        private readonly ICurrentUnitOfWorkProvider _currentUnitOfWorkProvider;

        public DapperActiveTransactionProvider(ICurrentUnitOfWorkProvider currentUnitOfWorkProvider)
        {
            _currentUnitOfWorkProvider = currentUnitOfWorkProvider;
        }

        public DbConnection GetConnection()
        {
            return _currentUnitOfWorkProvider.Current.GetActiveTransaction().Connection;
        }

        public DbTransaction GetTransaction()
        {
            return _currentUnitOfWorkProvider.Current.GetActiveTransaction().Transaction;
        }
    }
}
